<#ftl ns_prefixes={"orm": "http://java.sun.com/xml/ns/persistence/orm"}
	encoding="UTF-8" /><#recurse doc><#macro "orm:entity-mappings">
	<#global class = .node["orm:entity"].@class />
	<#global package = .node["orm:package"] />
</#macro>package ${package};

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import ${package}.${class};
import ${package}.${class}Dao;
import ${package}.${class}EditForm;
import ${package}.${class}ListForm;

import com.googlecode.horncomb.bean.paged.PagedList;
import com.googlecode.horncomb.bean.paged.PagedSetting;

/**
 * ${class} form service
 * <p>
 * 负责人/principal:<br/>
 * 修改记录/revision:<br/>
 * 日期:<br/>
 * 修改人:<br/>
 * 修改说明:<br/>
 * @author
 * @version $Id$
 */
public class ${class}FormService
{
    private ${class}Dao ${class?uncap_first}Dao;

    /**
     * ${class}列表
     * @param form
     *        表单对象
     * @return 列表页面数据
     * @throws Exception
     */
    public Map<String, Object> listReference(${class}ListForm form) throws Exception
    {
        Map<String, Object> ref = new HashMap<String, Object>();
        PagedSetting ps = form.getPagedSettingMap().values().iterator().next();
        PagedList<List<${class}>> result = this.${class?uncap_first}Dao.queryAll(ps
                .getOrder(), ps.getPage(), ps.getPageSize());
        ref.put("${class?uncap_first}List", result.getSource()); //$NON-NLS-1$
        ref.put("totalRows", result.getNrOfElements()); //$NON-NLS-1$
        return ref;
    }

    /**
     * 删除选中的项
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void deleteItems(${class}ListForm form) throws Exception
    {
        if (!form.getSelectedIds())
        {
	        this.${class?uncap_first}Dao.deleteByIds(form.getSelectedIds());
        }
    }

    /**
     * 获得${class}表单主对象
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void get(${class}EditForm form) throws Exception
    {
        if (form != null && StringUtils.hasText(form.getId()))
        {
            ${class} ${class?uncap_first} = this.${class?uncap_first}Dao.getById(form.getId());
            BeanUtils.copyProperties(${class?uncap_first}, form);
        }
    }

    /**
     * 显示编辑${class}界面相关数据
     * @param form
     *        表单对象
     * @return 显示页面数据
     * @throws Exception
     */
    public Map<String, Object> showReference(${class}EditForm form) throws Exception
    {
        // other reference data
        Map<String, Object> ref = new HashMap<String, Object>();
        return ref;
    }

    /**
     * 保存${class}表单
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void save(${class}EditForm form) throws Exception
    {
        this.${class?uncap_first}Dao.save(form);
    }

    /**
     * 删除单个${class}
     * @param form
     *        表单对象
     * @throws Exception
     */
    public void deleteItem(${class}EditForm form) throws Exception
    {
        this.${class?uncap_first}Dao.deleteById(form.getId());
    }

    /**
     * @param ${class?uncap_first}Dao
     *        the ${class?uncap_first}Dao to set
     */
    public void set${class}Dao(${class}Dao ${class?uncap_first}Dao)
    {
        this.${class?uncap_first}Dao = ${class?uncap_first}Dao;
    }
}
